class Solution {
public:
    vector<vector<string>> res;
    vector<string> path;

    bool isPalindrome(string s)
    {
        if(s.empty() || s.size()==1)
            return true;

        int left = 0;
        int right = s.size();
        while(left < right)
        {
            if(s[left] != s[right-1])
                return false;
            left++;
            right--;
        }

        return true;
    }

    void backtrack(string s, int start)
    {
        if(s.size() == start)
        {
            res.push_back(path);
            return;
        }

        for(int i = start; i < s.size(); i++)
        {
            string part = s.substr(start, i-start+1);
            if(!isPalindrome(part))
                continue;
            path.push_back(part);
            backtrack(s, i+1);
            path.pop_back();
        }
    }

    vector<vector<string>> partition(string s) {
        backtrack(s, 0);

        return res;
    }
};